package asteroids.model.programs.statements;

import exception.StopActionClassException;
import asteroids.model.programs.Expression;
import asteroids.model.programs.Program;

public class While extends Statement {
	
	public While(Expression<?> condition, Statement statement){
		this.condition=condition;
		this.statement=statement;
	}
	
	private Expression<?> condition;
	private Statement statement;
	

	@Override
	public void execute(Program program) throws StopActionClassException {
		if(!isExecuted()){
			if((Boolean)condition.getValue(program))
				statement.execute(program);
		}
		setExecuted();
	}

	@Override
	public void reset() {
		setUnexecuted();
		statement.reset();
	}

}
